package part3_The_Synchronized_Keyword;

public class App {

	private  int count=0;
	
	public synchronized void increment(){ // idea of synchronized method - when one thread execute this method , and another thread want to execute this method , this second thread must wait )
		count++;
	}
	
	public static void main(String[] args) {
		App app=new App();
		app.doWork();
	}

	
	public void doWork(){
		Thread t1=new Thread(new Runnable() {
			
			@Override
			public void run() {
				for(int i =0;i<10000;i++){
					increment();
				}
			}
		});
		
		Thread t2=new Thread(new Runnable() {
			
			@Override
			public void run() {
				for(int i =0;i<10000;i++){
					increment();
				}
			}
		});
		
		t1.start();
		t2.start();
		
		try {
			t1.join();
			t2.join();
			System.out.println();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		System.out.println("Count is "+count);
	
		System.out.println(Thread.currentThread().getName());
	}
}
